package dao

import javax.inject.Inject
import models.Tables._
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.jdbc.JdbcProfile

import scala.concurrent.{ExecutionContext, Future}

class MapDao @Inject()(protected val dbConfigProvider: DatabaseConfigProvider)
                      (implicit exec: ExecutionContext) extends
  HasDatabaseConfigProvider[JdbcProfile] {

  import profile.api._

  def insertLocation(row:Seq[LocationRow]) : Future[Unit] = {
    db.run(Location ++= row).map(_=>())
  }

  def insertArea(row:Seq[AreaRow]) : Future[Unit] = {
    db.run(Area ++= row).map(_=>())
  }

  def getAllLocation : Future[Seq[LocationRow]] = {
    db.run(Location.result)
  }

  def getByLocation(location:String) : Future[Seq[Int]] ={
    db.run(Location.filter(_.location === location).map(_.germId).result)
  }

  def getLocationByGermId(germId:Int) : Future[Seq[LocationRow]] = {
    db.run(Location.filter(_.germId === germId).result)
  }

  def getAreaByGermId(germId:Int) : Future[Seq[AreaRow]] = {
    db.run(Area.filter(_.germId === germId).result)
  }

}
